#ifndef __MY_MQTTCLIENT_H__
#define __MY_MQTTCLIENT_H__
#include "MQTTClient.h"

typedef enum{

    CONNECT = 1,
    DISCONNECT,
    SUB_OK,
    SUB_MESSAGE_OK,
    SUB_MESSAGE_ERR,
    PUB_MESSAGE_OK,
    PUB_MESSAGE_ERR,
}MyMqttClientEvent; 

class MyMqttClientMessage{
    public:
        MQTTClient_message message;
        MyMqttClientEvent event;
        const char* sub_topic;
        const char* pub_topic;
        int qos;
};

typedef void (*MyMqttClientCallback)(void*myclient,MyMqttClientMessage*msg,MyMqttClientEvent event);  


typedef struct 
{
    public:
	char address[100];   //mqtt server address for client
	char deviceid[50];   //device id of the union device station
	char key[100];       //key for the union device station

	//---------subcribe topic-----//
	char sub_realtime_data_back[100];   //real time data response 
	char sub_control_cmd[100];          //control cmd 
	char sub_parity_cmd[100];           //parity cmd 

	//----------publish topic-----//
	char pub_realtime[100];          
	char pub_control_cmd_back[100];
	char pub_parity_cmd_back[100];

	int qos;

    int inited = 0;

} MqttParam;

class MyMqttClient
{
private:
    MQTTClient_deliveryToken last_token;
    MQTTClient client = nullptr;
    int _sub(const char*sub_topic,int qos,MyMqttClientCallback cb);
public: 
    MqttParam mp;
    MyMqttClient(/* args */);
    ~MyMqttClient();

    MQTTClient get_client();
    //---------init client params-----------//
    int init_params(unsigned long id, char* key, char*addr);

    //---------client function--------------//
    int connect();
    int poll();
    int distroy();
    int pub(const char*topic,char*payload,int payloadlen);

    //--------client event------------------//
    MyMqttClientCallback on_connect = nullptr;
    MyMqttClientCallback on_disconnect = nullptr;
    MyMqttClientCallback on_sub = nullptr;
    MyMqttClientCallback on_recv = nullptr;
    MyMqttClientCallback on_pub = nullptr;
};



#endif // !__MY_MQTTCLIENT_H__

